<template>
  <TreeView style="height:800px; width:100%;overflow-y:auto;" :openerOpts="openerOpts" :model="model" :category="category" :selection="selection" :onSelect="onSelect" :display="display" :sort="sort" :search="search" :strategies="strategies" :transition="transition" :dragndrop="dragndrop" />
</template>

<script>
import { TreeView } from "@bosket/vue";
import { string } from "@bosket/tools";
import { dragndrop } from "@bosket/core";
const model = [
  {
    label: "工作台",
    path: "workbench"
  },
  {
    label: "管理",
    path: "manager"
  }
];
export default {
  name: "LeftMenuTree",
  components: {
    TreeView
  },
  model: {
    event: "selectionChange"
  },
  data() {
    return {
      // 显示标签
      labels: {
        "search.placeholder": "Search ..."
      },
      // 显示数据
      model: model,
      // Property of the model containing children
      // 由于是对象，所以使用items
      category: "items",
      // 初始化将没有选中如何元素
      selection: [],
      // On selection, update the parent selection array
      // 当选择一个items时的事件
      onSelect: items => {
        this.selection = items;
        // 提交selectionChange事件
        this.$emit("selectionChange", items);
      },

      // Custom display (with an anchor tag)
      // 显示渲染
      display: item => <a>{item.label}</a>,
      // 排序功能
      // Alphabetical sort
      sort: (a, b) => a.label.localeCompare(b.label),
      // Search by regex
      search: input => i => string(i.label).contains(input),
      strategies: {
        // Select on click
        click: ["select", "toggle-fold"],
        // Use keyboard modifiers
        selection: ["modifiers"],
        // Use the opener to control element folding
        fold: ["opener-control"]
      },
      // Transitions
      transition: {
        attrs: { appear: true },
        props: { name: "TreeViewTransition" }
      },
      // 展开时的箭头
      openerOpts: {
        // 位置
        position: "left",
        // 回调函数
        callback: (item, folded) => {
          console.log(`${item} is now ${folded ? "folded" : "unfolded"}`);
        }
      },
      // 拖拽
      dragndrop: {
        // 禁止拖拽
        draggable: false,
        // Use the "selection" drag and drop preset
        ...dragndrop.selection(
          () => this.model,
          m => {
            this.model = m;
          }
        ),
        // Add a custom image on drag
        drag: (_, event) => {
          event.dataTransfer.setDragImage(this.dragImage, 0, 0);
          event.dataTransfer.setData(
            "application/json",
            JSON.stringify(this.selection)
          );
        },
        // Drop only on categories or root (excluding asynchronous promises)
        droppable: _ => !_ || (_.items && _.items instanceof Array)
      }
    };
  }
};
</script>
<style lang="scss">
@charset "utf-8";
/* Search bar */

.TreeView > input[type="search"] {
  width: 100%;
  background: rgba(0, 0, 0, 0.05);
  height: 3em;
  border-width: 2px;
  transition: border 0.5s;
}

/* Elements */

.TreeView {
  white-space: nowrap;
}

.TreeView ul {
  list-style: none;
}

.TreeView li {
  min-width: 100px;
  transition: all 0.25s ease-in-out;
}

.TreeView ul li a {
  color: #222;
}

.TreeView ul li > .item > a {
  display: inline-block;
  vertical-align: middle;
  width: calc(100% - 155px);
  margin-right: 30px;
  padding: 10px 5px;
  text-decoration: none;
  transition: all 0.25s;
}

.TreeView ul li:not(.disabled) {
  cursor: pointer;
}

.TreeView ul li.selected > .item > a {
  //修改了点击时变为紫色
  color: rgb(97, 20, 220);
  font-weight: 700;
}

.TreeView ul li.selected > .item > a:hover {
  color: #aaa;
}
//修改了滑动时变为紫色
.TreeView ul li:not(.disabled) > .item > a:hover {
  color: #de6fe2;
}
// 右边的刷新操作

/* Root elements */

.TreeView ul.depth-0 {
  padding: 20px;
  margin: 0;
  background-color: rgba(255, 255, 255, 0.4);
  user-select: none;
  transition: all 0.25s;
}

/* Categories : Nodes with children */

.TreeView li.category > .item {
  display: block;
  margin-bottom: 5px;
  transition: all 0.25s ease-in-out;
}

.TreeView li.category:not(.folded) > .item {
  border-bottom: 1px solid crimson;
}

/* Category opener */

.TreeView .opener {
  display: inline-block;
  vertical-align: middle;
  font-size: 25px;
  cursor: pointer;
}

.TreeView .opener::after {
  // 箭头符号
  content: "+";
  display: block;
  transition: all 0.25s;
  font-family: monospace;
}

.TreeView li.category.async > .item > .opener::after {
  content: "\21BA";
}

.TreeView .opener:hover {
  color: #e26f6f;
}
// 点击后变为红色
/*.TreeView li.category:not(.folded) > .item {
  color: crimson;
  font-weight: 700;
}*/
.TreeView li.category:not(.folded) > .item > .opener::after {
  content: "-";
  color: crimson;
  // 旋转角度180度
  transform: rotate(180deg);
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.TreeView li.category.loading > .item > .opener::after {
  animation: spin 1s infinite;
}

/* Animations on fold / unfold */

.TreeViewTransition-enter,
.TreeViewTransition-leave-to {
  opacity: 0;
  transform: translateX(-50px);
}

.TreeViewTransition-enter-active,
.TreeViewTransition-leave-active {
  transition: all 0.3s ease-in-out;
}

/* Drag'n'drop */

.TreeView li.dragover,
.TreeView ul.dragover {
  box-shadow: 0px 0px 5px #ccc;
}

.TreeView ul.dragover {
  background-color: rgba(200, 200, 200, 0.3);
}

.TreeView li.dragover {
  background-color: rgba(100, 100, 100, 0.05);
  padding: 0px 5px;
}

.TreeView li.dragover > span.item {
  border-color: transparent;
}

.TreeView li.nodrop {
  box-shadow: 0px 0px 5px crimson;
  background-color: rgba(255, 20, 60, 0.1);
  padding: 0px 5px;
}
.TreeView {
  @import url("https://fonts.googleapis.com/css?family=Open+Sans:400,600|Cormorant+Garamond:400, 600");
  :root {
    --lightColor: #eee;
    --lighterColor: #fff;
    --darkColor: #888;
    --darkerColor: #333;
    --accentColor: #dc143c;
    --accentColorLight: #ff6262;
    --emphasisColor: rgba(255, 235, 59, 0.4);
    --serifFont: "Cormorant Garamond", serif;
    --sansSerifFont: "Open Sans", sans-serif;
  }
  #framework-root,
  .App .chapter {
    background-color: var(--lighterColor);
  }
  .App .chapter {
    color: var(--darkerColor);
    font-size: 0.9em;
  }
  @media (max-width: 600px) {
    .App .chapter {
      margin-bottom: 2px;
    }
  }
  .App .chapter h1 {
    padding: 0.5em 0;
  }
  :root {
    --lightColor: #eee;
    --lighterColor: #fff;
    --darkColor: #888;
    --darkerColor: #333;
    --accentColor: #dc143c;
    --accentColorLight: #ff6262;
    --emphasisColor: rgba(255, 235, 59, 0.4);
    --serifFont: "Cormorant Garamond", serif;
    --sansSerifFont: "Open Sans", sans-serif;
  }
  :root {
    --lightColor: #eee;
    --lighterColor: #fff;
    --darkColor: #888;
    --darkerColor: #333;
    --accentColor: #dc143c;
    --accentColorLight: #ff6262;
    --emphasisColor: rgba(255, 235, 59, 0.4);
    --serifFont: "Cormorant Garamond", serif;
    --sansSerifFont: "Open Sans", sans-serif;
  }

  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }
    to {
      transform: rotate(1turn);
    }
  }
  .TreeViewWindow {
    text-align: center;
  }
  .TreeViewWindow div.select-blocks > button {
    border: 1px solid #444;
    font-size: 0.9em;
    border-radius: 0;
    margin-right: 5px;
  }
  .TreeViewWindow div.select-blocks > button:hover {
    border-color: transparent;
  }
  code[class*="language-"],
  pre[class*="language-"] {
    color: #ccc;
    background: none;
    font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace;
    text-align: left;
    white-space: pre;
    word-spacing: normal;
    word-break: normal;
    word-wrap: normal;
    line-height: 1.5;
    tab-size: 4;
    -webkit-hyphens: none;
    hyphens: none;
  }
  pre[class*="language-"] {
    padding: 1em;
    margin: 0.5em 0;
    overflow: auto;
  }
  :not(pre) > code[class*="language-"],
  pre[class*="language-"] {
    background: #2d2d2d;
  }
  :not(pre) > code[class*="language-"] {
    padding: 0.1em;
    border-radius: 0.3em;
    white-space: normal;
  }
  :root {
    --lightColor: #eee;
    --lighterColor: #fff;
    --darkColor: #888;
    --darkerColor: #333;
    --accentColor: #dc143c;
    --accentColorLight: #ff6262;
    --emphasisColor: rgba(255, 235, 59, 0.4);
    --serifFont: "Cormorant Garamond", serif;
    --sansSerifFont: "Open Sans", sans-serif;
  }
  body,
  html {
    overflow-x: hidden;
    overflow-y: scroll;
  }
  body {
    margin: 0;
    padding: 0;
    font-family: var(--sansSerifFont);
    background: var(--darkerColor);
    letter-spacing: 0.3px;
    -webkit-overflow-scrolling: touch;
  }
  [disabled] {
    pointer-events: none;
    cursor: auto;
    color: gray;
    background: #d3d3d3 !important;
  }
  a.anchor-button,
  button {
    font-size: 0.7em;
    border: none;
    outline: none;
    padding: 7px 10px;
    cursor: pointer;
    transition: all 0.25s ease-in-out;
  }
  a.anchor-button:hover:not([disabled]),
  button:hover:not([disabled]) {
    background: var(--accentColorLight);
    color: #fff;
  }
  a.anchor-button > i,
  button > i {
    margin-right: 10px;
  }
  a.anchor-button.basic-button,
  button.basic-button {
    background: var(--accentColor);
    color: #fff;
    border-radius: 5px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 0 2px #999;
  }
  a.anchor-button.basic-button:hover:not([disabled]),
  button.basic-button:hover:not([disabled]) {
    box-shadow: none;
  }
  a.anchor-button.control-button,
  button.control-button {
    border: 1px solid #000;
    background: var(--lighterColor);
  }
  a {
    cursor: pointer;
    text-decoration: inherit;
    color: inherit;
    transition: color 0.25s ease-in-out;
  }
  a:hover {
    color: var(--accentColor);
  }
  input[type="email"],
  input[type="number"],
  input[type="search"],
  input[type="text"] {
    -webkit-appearance: none;
    border: none;
    outline: none;
    border-bottom: 1px solid var(--darkerColor);
    border-radius: 0;
    padding: 5px 10px;
    transition: border 0.25s ease-in-out;
  }
  input[type="email"]:focus,
  input[type="number"]:focus,
  input[type="search"]:focus,
  input[type="text"]:focus {
    border-color: var(--accentColor);
  }

  .inline-row {
    padding: 20px;
  }
  .inline-row > * {
    margin: 0 15px;
  }
  .inline-row > *,
  .inline-row > form > * {
    display: inline-block;
    vertical-align: middle;
  }
  .inline-row > form > * {
    padding: 5px 10px;
    font-weight: 100;
  }
  .shadow-icon {
    margin-right: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 1em;
    height: 1em;
    width: 1em;
    background: rgba(0, 0, 0, 0.3);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  }
  .serif,
  ul.highlight-list {
    font-family: var(--serifFont);
  }
  ul.highlight-list {
    padding-left: 0;
    list-style: none;
  }
  ul.highlight-list li {
    border-left: 5px solid var(--accentColor);
    padding-left: 15px;
    margin-bottom: 20px;
  }
  ul.pick-list {
    padding-left: 0;
    list-style: none;
  }
  ul.pick-list h5 {
    border-left: 2px solid var(--accentColor);
    padding: 5px 15px !important;
    font-family: var(--serifFont);
  }
  pre.itemType {
    font-family: Monaco, Courier New, monospace;
    padding: 5px 0;
    border-bottom: 1px dashed var(--darkerColor);
    white-space: pre-wrap;
  }
  .tree-sample {
    border: 2px solid var(--darkerColor);
    margin: 5px 0;
  }
  .tree-sample li > .item {
    cursor: pointer;
    display: block;
    padding: 2px 5px;
    transition: all 0.25s;
  }
  .tree-sample li.dragover > .item,
  .tree-sample li[draggable="true"] > .item:hover {
    background-color: crimson;
    color: #fff;
  }
  .iframe-hide {
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    cursor: pointer;
    color: #bbb;
    opacity: 0.6;
    border-radius: 5px;
    background-image: repeating-linear-gradient(
      145deg,
      #222,
      #222 50px,
      #444 0,
      #444 100px
    );
    transition: all 0.3s;
  }
  .iframe-hide > span:after {
    content: "";
    background-color: #fff;
    height: 2px;
    width: 0;
    margin-top: 2px;
    transition: all 0.3s;
    display: block;
  }
  .iframe-hide:hover {
    opacity: 1;
    color: #fff;
  }
  .iframe-hide:hover > span:after {
    width: 100%;
  }
  /* # sourceMappingURL=common.css.map */
}
</style>
